2416d7
@@ -187,7 +187,6 @@
public class HFileBlockDefaultEncodingContext implements
         Preconditions.checkState(ivLength <= Byte.MAX_VALUE, "IV length out of range");
         cryptoByteStream.write(ivLength);
         if (ivLength > 0) {
-          Encryption.incrementIv(iv);
           encryptor.setIv(iv);
           cryptoByteStream.write(iv);
         }
@@ -197,6 +196,9 @@
public class HFileBlockDefaultEncodingContext implements
 
         onDiskBytesWithHeader = cryptoByteStream.toByteArray();
 
+        // Increment the IV given the final block size
+        Encryption.incrementIv(iv, 1 + (onDiskBytesWithHeader.length / encryptor.getBlockSize()));
+
       } else {
 
         cryptoByteStream.write(0);
